package fr.esiag.isidis.epp.service;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import fr.esiag.isidis.epp.model.CDCModel;
import fr.esiag.isidis.epp.model.WeightModel;
import fr.esiag.isidis.epp.repository.CDCAndWeightRepository;

@Service
public class CDCAndWeightService {

	private static Logger logger = Logger.getLogger(CDCAndWeightService.class);

	@Autowired
	private CDCAndWeightRepository cdcAndWeightRepository;


	
	public void loadCsvFile() throws Exception
	{
		List<CDCModel> items = cdcAndWeightRepository.cdc_extractFromCsvFile();
		List<WeightModel> items2 = cdcAndWeightRepository.weight_extractFromCsvFile();

		for(CDCModel item : items)
		{
			cdcAndWeightRepository.loadCdc(item);
			logger.debug("Insertion de l'item cdc " + item);
		}
		
		for(WeightModel item: items2)
		{
			cdcAndWeightRepository.loadWeight(item);
			logger.debug("Insertion de l'item weight " + item);
		}
	}
}
